package com.example.wm.controller;

import ch.qos.logback.core.net.SyslogOutputStream;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.wm.common.Result;
import com.example.wm.common.ResultData;
import com.example.wm.entity.HenDeiShunoutorinStrorage;
import com.example.wm.mapper.HenDeiShunoutorinStrorageMapper;
import com.example.wm.service.HenDeiShunoutorinStrorageService;
import com.example.wm.utils.TsyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Slf4j
@RestController
@RequestMapping("/HenDeiShunoutorinStrorage")
//恒德顺出入库
public class HenDeiShunoutorinStrorageController {
    @Resource
    private HenDeiShunoutorinStrorageService henDeiShunoutorinStrorageService;
    @Resource
    private HenDeiShunoutorinStrorageMapper henDeiShunoutorinStrorageMapper;
    @Resource
    private TsyUtils tsyUtils;
    @PostMapping("/insert")
    public Result  insert(@RequestBody HenDeiShunoutorinStrorage henDeiShunoutorinStrorage){

            henDeiShunoutorinStrorage.setJktime(tsyUtils.getnowtime());

        henDeiShunoutorinStrorageService.save(henDeiShunoutorinStrorage);
        return ResultData.success("插入成功");
    }

    @PostMapping("/finde")
    public Result  finde(@RequestBody HenDeiShunoutorinStrorage henDeiShunoutorinStrorage){
        LambdaQueryWrapper<HenDeiShunoutorinStrorage> lq=new LambdaQueryWrapper<>();
        lq.eq(HenDeiShunoutorinStrorage::getStatus,henDeiShunoutorinStrorage.getStatus());

      List<HenDeiShunoutorinStrorage> list=  henDeiShunoutorinStrorageService.list(lq);
        return ResultData.success(list);
    }
    @PostMapping("/update")
    public Result update(@RequestBody HenDeiShunoutorinStrorage henDeiShunoutorinStrorage){
        if(Objects.equals(henDeiShunoutorinStrorage.getStatus(), "已入库") || Objects.equals(henDeiShunoutorinStrorage.getStatus(), "已保存")){
            henDeiShunoutorinStrorage.setJktime(tsyUtils.getnowtime());
        }
System.out.println(henDeiShunoutorinStrorage);

        if(Objects.equals(henDeiShunoutorinStrorage.getStatus(), "已出库")){
            henDeiShunoutorinStrorage.setCktime(tsyUtils.getnowtime());
        }
     Boolean b=   henDeiShunoutorinStrorageService.updateById(henDeiShunoutorinStrorage);
     return  ResultData.success(b);


    }
//搜索
    @PostMapping("/findbycarnum")
    public Result findbycarnum(@RequestBody HenDeiShunoutorinStrorage henDeiShunoutorinStrorage){
        LambdaQueryWrapper<HenDeiShunoutorinStrorage> lq=new LambdaQueryWrapper<>();
        lq.eq(HenDeiShunoutorinStrorage::getStatus,"已入库");
        lq.like(HenDeiShunoutorinStrorage::getCartport,henDeiShunoutorinStrorage.getCartport());
        List<HenDeiShunoutorinStrorage> list=  henDeiShunoutorinStrorageService.list(lq);

        return  ResultData.success(list);


    }
    //已入库
    @PostMapping("/findin")
    public Result findin(){
        LambdaQueryWrapper<HenDeiShunoutorinStrorage> lq=new LambdaQueryWrapper<>();
        lq.eq(HenDeiShunoutorinStrorage::getStatus,"已入库");
        List<HenDeiShunoutorinStrorage> list=  henDeiShunoutorinStrorageService.list(lq);
        return  ResultData.success(list);


    }

    @PostMapping("/findinnotout")
    public Result findinnotout(){
        LambdaQueryWrapper<HenDeiShunoutorinStrorage> lq=new LambdaQueryWrapper<>();
        lq.ne(HenDeiShunoutorinStrorage::getStatus,"已出库");
        List<HenDeiShunoutorinStrorage> list=  henDeiShunoutorinStrorageService.list(lq);






        return  ResultData.success(list);


    }
}
